
<template>
  <div class="sampCard-wrapper">
    <!-- 发卡取样dialog-->
    <el-dialog
      :title="title"
      :close-on-click-modal="false"
      v-dialogDrag
      :visible.sync="editVisible"
    >
      <el-form
        :inline="true"
        label-width="82px"
        :rules="dataRule"
        ref="sampCardForm"
        :model="sampCardForm"
        style="position: relative;min-width:704px"
      >
        <span class="first-form">
          <el-form-item label="卡序号:" prop="cardNumber">
            <el-input v-model="readCardForm.cardNumber"></el-input>
          </el-form-item>

          <el-form-item label="卡类型:" prop="cardType">
            <el-input v-model="readCardForm.cardTypeValue">
            </el-input>
          </el-form-item>
        </span>

        <div class="readBut" @click="readCard">
          读卡
        </div>
        <div></div>
        <span class="first-form">
          <el-form-item label="卡内号:" prop="cardInnerNumber">
            <el-input v-model="readCardForm.cardInnerNumber"></el-input>
          </el-form-item>
          <el-form-item label="卡状态:" prop="state">
            <el-input v-model="readCardForm.cardStateValue">
            </el-input>
          </el-form-item>
        </span>
        <div></div>
        <span class="second-form">
          <el-form-item class="card-use" label="卡用途:" prop="cardUsage">
              取样
          </el-form-item>
        </span>
        <div></div>
        <el-form-item label="备注:"  style="margin-bottom: 0 !important;">
          <el-input
                    type="textarea"
                    placeholder="请输入内容"
                    v-model="sampCardForm.remark"
                    maxlength="50"
          >
          </el-input> </el-form-item>
        <span class="second-form"> </span>
      </el-form>
      <span slot="footer" class="dialog-footer">
        <el-button size="small" type="primary" @click="doSubmit()" v-noMoreClick
        >确定</el-button
        >
        <el-button size="small" @click="close()">取消</el-button>
      </span>
    </el-dialog>
  </div>
</template>
<script>
  import { send } from '@/api/truck/cardRegiste/cardRegiste.js'
  import { edit } from '@/api/truck/cardOperate/cardOperate.js'
  export default {
    components: {},
    data () {
      return {
        readCardId: '779023081128783872',
        method: '',
        detailsVisible: false,
        title: '',
        sampCardForm: {
          cardNumber: '',
          cardInnerNumber: '',
          state: '',
          operateType: '',
          remark: '',
          id: ''
        },
        readCardForm: {
          cardNumber: '',
          cardInnerNumber: '',
          cardType: '',
          cardTypeValue: '',
          cardState: '',
          cardStateValue: '',
          id: ''
        },
        editVisible: false,
        dataRule: {
        }
      }
    },
    methods: {
    	handleClose(done) {
			this.$Msg.confirm({
				title:'您确定要关闭吗？',
				content:this.GLOBAL.FORM_CLOSE_TIPS,
				confirmCall:()=>{
					done();
				}
			})
		},
      init (method, sampCardForm) {
        if (method === 'add') {
          this.editVisible = true
          this.$nextTick(() => {
            this.$refs.sampCardForm.resetFields()
            this.sampCardForm = {}
          })

          this.sampCardForm.id = ''
          this.sampCardForm.addressId = ''
          this.title = '发卡'
        }
      },
      close () {
        this.editVisible = false
      },
      readCard () {
        send({
          id: this.readCardId
        }).then(({data}) => {
          if (data.code === '200') {
            this.readCardForm = data.result
            this.readCardForm.cardTypeValue = this.$dictUtils.getDictLabel('cardType', this.readCardForm.cardType, '')
            this.readCardForm.cardStateValue = this.$dictUtils.getDictLabel('cardState', this.readCardForm.state, '')
          }
          this.loading = false
        })
      },
      doSubmit () {
        this.$refs['sampCardForm'].validate((valid) => {
          if (valid) {
            this.sampCardForm.cardNumber = this.readCardForm.cardNumber
            this.sampCardForm.cardInnerNumber = this.readCardForm.cardInnerNumber
            this.sampCardForm.state = this.readCardForm.state
            this.sampCardForm.cardUsage = 3
            this.sampCardForm.cardRegisterId = this.readCardForm.id
            this.$set(this.sampCardForm, 'props', 2)
            edit(this.sampCardForm).then(({data}) => {
              if (data.code === '200') {
                this.$message({
                  message: '发卡成功',
                  type: 'success'
                })
                this.editVisible = false
                this.$emit('refreshDataList')
              }
            })
          }
        })
      }
    }
  }
</script>
<style lang="scss" scoped>
  .first-form ::v-deep .el-input__inner {
    width: 170px;
  }
  .second-form ::v-deep .el-input__inner {
    width: 246px;
  }
  .readBut {
    width: 130px;
    height: 65px;
    background: #1890ff;
    border-radius: 5px;
    position: absolute;
    right: 24px;
    top: 10px;
    font-weight: 400;
    color: #ffffff;
    text-align: center;
    line-height: 65px;
    cursor:pointer;
    font-size: 29px;
    font-family: Microsoft YaHei;
  }
  .view-container {
    margin-bottom: 20px;
    display: flex;
    .label-container {
      width: 150px;
      text-align: right;
      font-size: 16px;
      font-weight: 400;
      color: #666666;
    }
    .form-container {
      font-size: 14px;
      font-weight: 400;
      color: #333333;
      width: 200px;
    }
  }
  .sampCard-wrapper{
    ::v-deep.el-dialog .el-dialog__body .el-form{
      .second-form{
        .el-form-item.card-use{
          margin-bottom: 20px !important;
          .el-form-item__content{
            font-size: 16px;
          }
        }
        .el-input.el-input-group{
          .el-input__inner{
            width: 206px;
            border-right: none;
            border-top-right-radius: 0;
            border-bottom-right-radius: 0;
          }
          .el-input-group__append{
            width: 40px;
            padding: 0;
            text-align: center;
            border: 1px solid #AAAAAA;
            position: relative;
            left: -1px;
            font-size: 14px;
            font-family: Microsoft YaHei;
            font-weight: 400;
            color: #1890FF;
            background: #FFFFFF;
          }
        }
        .el-form-item:nth-child(2){
          margin-left: 15px;
        }
      }
      .el-form-item{
        .el-textarea{
          width: 620px;
          .el-textarea__inner{
            resize: none;
            height: 92px;
            border: 1px solid #AAAAAA;
            border-radius: 4px;
            font-family:Arial;
          }
        }

      }
    }
  }
</style>
